package controllers.playerControlers;

import game.Game;

import java.util.HashSet;

import classes.cards.CityCard;
import classes.cards.ICard;
import classes.cards.IPlayerCard;
import classes.cards.PlayerCityCard;
import classes.city.City;
import classes.diseases.Disease;
import classes.players.Player;

public class PlayerController {

	// movement actions methods

	public static void drive(Player player, City city) {
		player.setLocation(city);
	}

	public void directFlight(Player player, PlayerCityCard playerCityCard) {
		player.setLocation(playerCityCard.getCity());
		;
	}

	public void charterFlight(Player player, City city) {
		player.setLocation(city);
	}

	public void shuttleFlight(Player player, City city) {
		player.setLocation(city);
	}

	// other actions methods

	public void buildReserachStation(Player player) {
		player.getLocation().setHasResearchCentre(true);
		discardCard(player, player.getHand().get(player.getLocation().getName()));
	}

	public void treatDisease(Player player) {
		if (player.getLocation().getInfectionLevel() > 0) {
			if (player.getLocation().getDisease().getIsCured()) {
				player.getLocation().setInfectionLevel(0);
			} else {
				player.getLocation().setInfectionLevel((player.getLocation()
						.getInfectionLevel() - 1));
			}
		}
	}

	public void discoverACure(Player player, Disease disease) {
		player.getLocation().getDisease().setCured(true);
		int count = 5;
		for (IPlayerCard card : player.getHand().values()) {
			if (card instanceof CityCard) {
				if (((CityCard) card).getDisease().equals(disease)) {
					discardCard(player, card);
					count--;
				}
			}
			if (count == 0) {
				break;
			}
		}
	}

	public void recieveKnowledge(Player player, Player otherPlayer, IPlayerCard cityCard) {
		player.getHand().put(((CityCard) cityCard).getName(), cityCard);
		otherPlayer.getHand().remove(((CityCard) cityCard).getName());
	}

	public void shareKnowledge(Player player, Player otherPlayer, PlayerCityCard cityCard) {
		otherPlayer.getHand().put(((CityCard) cityCard).getName(), cityCard);
		player.getHand().remove(((CityCard) cityCard).getName());
	}

	// other methods
	
	public static void drawCard(Player player) {
		IPlayerCard card = Game.getInstance().getPlayerDeck().getPlayerDeckController().drawCard(Game.getInstance().getPlayerDeck());
		player.getHand().put(card.getName(), card);	
	}
	
	public static void discardCard(Player player, IPlayerCard card) {
		Game.getInstance().getPlayerDeck().getPlayerDeckController().addToDiscardPile(Game.getInstance().getPlayerDeck(), card);
		player.getHand().remove(card.getName());
	}
	
}
